package com.taijia.chapter6;

public class StringBufferTest {
	
	public static long combine(int num,String str) {
		long timeStart = System.currentTimeMillis();
		if(num<=0) 
			return 0;
		String result = "";
		for(int i=0;i<num;i++) {
			result += str;
		}
		return System.currentTimeMillis()-timeStart;
	}
	
	public static long combine(int num,StringBuffer sb) {
		long timeStart = System.currentTimeMillis();
		if(num<=0) 
			return 0;
		StringBuffer result = new StringBuffer();
		for(int i=0;i<num;i++) {
			result.append(sb);
		}
		return System.currentTimeMillis()-timeStart;
	}
	
	public static void main(String[] args) {
		// 查看效率差别
		final int NUM = 50000;
		final String STR = "5元现金返还";
		System.out.println(combine(NUM, STR)); //5471
		System.out.println(combine(NUM, new StringBuffer(STR))); //15
	}
}
